part of _;

extension on LoginPage {
  Widget view_topBar() {
    return Container(
      margin: EdgeInsets.only(top: yStatubarHeight()),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          YButton(
            onTap: () => yFinish(),
            width: yNavBarHeight(),
            height: yNavBarHeight(),
            child: Icon(Icons.close),
          ),
          YExpanded(),
          YButton(height: yNavBarHeight(), child: Text("更多选项"), onTap: () => controller_showMoreFunc()),
        ],
      ),
    );
  }

  Widget view_title() {
    return Row(
      children: [
        Text("没有账户？", style: TextStyle(color: Colors.grey)),
        GestureDetector(
          onTap: () => yIntent(RegisterPage(), intentType: YIntentType.Present_Replace),
          child: Text("立即注册", style: TextStyle(color: YConfig.themeColor)),
        ),
      ],
    );
  }

  Widget view_protocol() {
    return GestureDetector(
      onTap: () => setState(() => isSelectProtocol = !isSelectProtocol),
      child: Row(
        children: [
          Checkbox(value: isSelectProtocol, onChanged: (value) => setState(() => isSelectProtocol = value!)),
          MyViews.view_protocol(yPage),
        ],
      ),
    );
  }

  Widget view_login() {
    return YButton(
      width: yScreenSize().width,
      height: 50,
      borderRadius: BorderRadius.circular(99),
      decoration: BoxDecoration(gradient: IFinal.Colors.btnThemeGradient),
      child: Text("登录", style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold)),
      onTap: () => controller_login(),
    );
  }

  Widget view_main() {
    switch (loginType) {
      case Enum_LoginType.Account:
        return Column(
          children: [
            TextFormField(
              controller: textController_account_loginname,
              decoration: InputDecoration(
                hintText: "请输入用户名",
                hintStyle: TextStyle(color: Colors.grey),
                enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey.shade400)),
              ),
              focusNode: focusNode_loginname,
            ),
            YSpacer(height: 20),
            TextFormField(
              controller: textController_account_password,
              obscureText: !isShowPassword,
              decoration: InputDecoration(
                hintText: "请输入密码",
                hintStyle: TextStyle(color: Colors.grey),
                enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey.shade400)),
                suffixIcon: YButton(
                  width: 50,
                  child: Image.asset(isShowPassword ? "images/ic_eye_open.png" : "images/ic_eye_close.png", width: 20),
                  onTap: () => setState(() => isShowPassword = !isShowPassword),
                ),
              ),
            ),
            YSpacer(height: 20),
            TextFormField(
              controller: textController_account_code,
              decoration: InputDecoration(
                hintText: "请输入验证码",
                hintStyle: TextStyle(color: Colors.grey),
                enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey.shade400)),
                suffixIcon: codeParams == null || codeParams!.isEmpty
                    ? YEmpty()
                    : GestureDetector(
                        child: Container(
                          padding: EdgeInsets.all(5),
                          child: YImage(null, 0, "${IFinal.Others.BaseIP}${IFinal.Urls.verifyCode}$codeParams"),
                        ),
                        onTap: () => controller_refreshCode(),
                      ),
              ),
            ),
            YSpacer(height: 30),
            view_login(),
          ],
        );
      case Enum_LoginType.Third:
        return Row(
          children: [
            Expanded(
              child: YButton(
                height: (yScreenSize().width - 20) / 2,
                child: Image.asset("images/icon_qq.png", width: 80),
                onTap: () => controller_login(thirdPlatform: ShareSDKPlatforms.qq),
              ),
            ),
            Expanded(
              child: YButton(
                height: (yScreenSize().width - 20) / 2,
                child: Image.asset("images/icon_wechat.png", width: 80),
                onTap: () => controller_login(thirdPlatform: ShareSDKPlatforms.wechatSession),
              ),
            ),
          ],
        );
      case Enum_LoginType.Verify:
        return Column(
          children: [
            view_login(),
          ],
        );
      case Enum_LoginType.Code_server:
        return Column(
          children: [
            TextFormField(
              controller: textController_code_server_phone,
              keyboardType: TextInputType.phone,
              decoration: InputDecoration(
                hintText: "请输入手机号",
                hintStyle: TextStyle(color: Colors.grey),
                enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey.shade400)),
              ),
            ),
            YSpacer(height: 20),
            TextFormField(
              controller: textController_code_server_code,
              keyboardType: TextInputType.number,
              decoration: InputDecoration(
                hintText: "请输入短信验证码",
                hintStyle: TextStyle(color: Colors.grey),
                enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey.shade400)),
                suffixIcon: YButton(
                  width: 120,
                  child: Text(codeTimeLeft > 0 ? "${codeTimeLeft}s后获取" : "获取Server验证码"),
                  enable: codeTimeLeft <= 0,
                  onTap: () => AppUtils.send_sms_server(yPage, textController_code_server_phone.text, () => controller_runSmsTimer()),
                ),
              ),
            ),
            YSpacer(height: 30),
            view_login(),
          ],
        );
      case Enum_LoginType.Code_sdk:
        return Column(
          children: [
            TextFormField(
              controller: textController_code_sdk_phone,
              keyboardType: TextInputType.phone,
              decoration: InputDecoration(
                hintText: "请输入手机号",
                hintStyle: TextStyle(color: Colors.grey),
                enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey.shade400)),
              ),
            ),
            YSpacer(height: 20),
            TextFormField(
              controller: textController_code_sdk_code,
              keyboardType: TextInputType.number,
              decoration: InputDecoration(
                hintText: "请输入短信验证码",
                hintStyle: TextStyle(color: Colors.grey),
                enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey.shade400)),
                suffixIcon: YButton(
                  width: 120,
                  child: Text(codeTimeLeft > 0 ? "${codeTimeLeft}s后获取" : "获取SDK验证码"),
                  enable: codeTimeLeft <= 0,
                  onTap: () => AppUtils.send_sms_sdk(textController_code_server_phone.text, () => controller_runSmsTimer()),
                ),
              ),
            ),
            YSpacer(height: 30),
            view_login(),
          ],
        );
      default:
        return Text("尚未支持的登录方式");
    }
  }
}
